package frame;

import Beans.SchedulingMethods;

import java.util.concurrent.locks.Lock;

public class insertToReady implements Runnable{
    public final Lock firstLock;
    public Lock secondLock;
    insertToReady(Lock lock1,Lock lock2){
        firstLock = lock1;
        secondLock = lock2;
    }
    @Override
    public void run() {
        while(true){
            firstLock.lock();
            boolean success;
            while(!SchedulingMethods.ReadyIsFull(MainFrame.readyQueue)) {  //当ready队列不满时添加进程
                MainFrame.getNewData(MainFrame.newTable, MainFrame.newQueue);
                success = SchedulingMethods.insertToReady(MainFrame.readyQueue, MainFrame.newQueue);
                MainFrame.getNewData(MainFrame.newTable, MainFrame.newQueue);
                MainFrame.getReadyData(MainFrame.readyTable, MainFrame.readyQueue);
                if(!success)  //当添加进程失败时运行剩余的进程
                    break;
            }
            firstLock.unlock();
        }
    }
}
